package Stream流学习;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Stream流collection方法学习
 *
 * @Author: SunAo
 * @Date: 2021/2/4 19:30
 */
public class collection {

    @Test
    public void List转Set(){
        List<String> list = Arrays.asList("a", "b", "c");
        Set<String> set = list.stream().collect(Collectors.toSet());
        set.forEach(System.out::println);
    }

    @Test
    public void List链接起来(){
        List<String> list = Arrays.asList("A", "B", "C");
        String str = list.stream().collect(Collectors.joining(","));
        System.out.println(str);
    }
    @Test
    public void List链接起来2(){
        List<Integer> list = Arrays.asList(1, 2, 3);
        String str = list.stream().map(s->s.toString()).collect(Collectors.joining(","));
        System.out.println(str);
    }

}
